from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-17 14:08:13.426137
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 17, Aug, 2022
Time: 14:08:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1483
Nobs: 751.000 HQIC: -50.4887
Log likelihood: 9538.04 FPE: 9.55765e-23
AIC: -50.7021 Det(Omega_mle): 8.48493e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294784 0.055214 5.339 0.000
L1.Burgenland 0.107933 0.036671 2.943 0.003
L1.Kärnten -0.106681 0.019449 -5.485 0.000
L1.Niederösterreich 0.206173 0.076528 2.694 0.007
L1.Oberösterreich 0.112911 0.074708 1.511 0.131
L1.Salzburg 0.253537 0.039205 6.467 0.000
L1.Steiermark 0.039394 0.051124 0.771 0.441
L1.Tirol 0.106455 0.041456 2.568 0.010
L1.Vorarlberg -0.060837 0.035579 -1.710 0.087
L1.Wien 0.051036 0.066120 0.772 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061516 0.115096 0.534 0.593
L1.Burgenland -0.033963 0.076442 -0.444 0.657
L1.Kärnten 0.047373 0.040542 1.169 0.243
L1.Niederösterreich -0.177031 0.159526 -1.110 0.267
L1.Oberösterreich 0.408546 0.155732 2.623 0.009
L1.Salzburg 0.287226 0.081724 3.515 0.000
L1.Steiermark 0.107934 0.106570 1.013 0.311
L1.Tirol 0.311243 0.086417 3.602 0.000
L1.Vorarlberg 0.025284 0.074165 0.341 0.733
L1.Wien -0.030437 0.137830 -0.221 0.825
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189315 0.028341 6.680 0.000
L1.Burgenland 0.089351 0.018823 4.747 0.000
L1.Kärnten -0.008476 0.009983 -0.849 0.396
L1.Niederösterreich 0.259047 0.039282 6.595 0.000
L1.Oberösterreich 0.140758 0.038348 3.671 0.000
L1.Salzburg 0.044687 0.020124 2.221 0.026
L1.Steiermark 0.019297 0.026242 0.735 0.462
L1.Tirol 0.091592 0.021279 4.304 0.000
L1.Vorarlberg 0.057837 0.018263 3.167 0.002
L1.Wien 0.117760 0.033940 3.470 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106571 0.028762 3.705 0.000
L1.Burgenland 0.045980 0.019103 2.407 0.016
L1.Kärnten -0.013979 0.010131 -1.380 0.168
L1.Niederösterreich 0.189769 0.039865 4.760 0.000
L1.Oberösterreich 0.300418 0.038917 7.719 0.000
L1.Salzburg 0.109895 0.020423 5.381 0.000
L1.Steiermark 0.103885 0.026632 3.901 0.000
L1.Tirol 0.106516 0.021596 4.932 0.000
L1.Vorarlberg 0.068742 0.018534 3.709 0.000
L1.Wien -0.018690 0.034444 -0.543 0.587
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127918 0.052410 2.441 0.015
L1.Burgenland -0.050809 0.034809 -1.460 0.144
L1.Kärnten -0.040498 0.018461 -2.194 0.028
L1.Niederösterreich 0.170288 0.072642 2.344 0.019
L1.Oberösterreich 0.141904 0.070914 2.001 0.045
L1.Salzburg 0.288118 0.037214 7.742 0.000
L1.Steiermark 0.034160 0.048528 0.704 0.481
L1.Tirol 0.161747 0.039351 4.110 0.000
L1.Vorarlberg 0.100766 0.033772 2.984 0.003
L1.Wien 0.068447 0.062763 1.091 0.275
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055286 0.041698 1.326 0.185
L1.Burgenland 0.040096 0.027694 1.448 0.148
L1.Kärnten 0.050772 0.014688 3.457 0.001
L1.Niederösterreich 0.217777 0.057794 3.768 0.000
L1.Oberösterreich 0.294712 0.056420 5.224 0.000
L1.Salzburg 0.043496 0.029608 1.469 0.142
L1.Steiermark 0.000565 0.038609 0.015 0.988
L1.Tirol 0.144535 0.031308 4.617 0.000
L1.Vorarlberg 0.071474 0.026869 2.660 0.008
L1.Wien 0.081989 0.049934 1.642 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.176564 0.049915 3.537 0.000
L1.Burgenland -0.003687 0.033152 -0.111 0.911
L1.Kärnten -0.062118 0.017583 -3.533 0.000
L1.Niederösterreich -0.080851 0.069184 -1.169 0.243
L1.Oberösterreich 0.194441 0.067539 2.879 0.004
L1.Salzburg 0.056931 0.035443 1.606 0.108
L1.Steiermark 0.232809 0.046218 5.037 0.000
L1.Tirol 0.495777 0.037478 13.229 0.000
L1.Vorarlberg 0.046803 0.032164 1.455 0.146
L1.Wien -0.054321 0.059775 -0.909 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164361 0.057524 2.857 0.004
L1.Burgenland -0.010823 0.038205 -0.283 0.777
L1.Kärnten 0.067314 0.020263 3.322 0.001
L1.Niederösterreich 0.205753 0.079730 2.581 0.010
L1.Oberösterreich -0.066134 0.077834 -0.850 0.396
L1.Salzburg 0.210052 0.040845 5.143 0.000
L1.Steiermark 0.117488 0.053263 2.206 0.027
L1.Tirol 0.069911 0.043191 1.619 0.106
L1.Vorarlberg 0.121453 0.037067 3.277 0.001
L1.Wien 0.122256 0.068887 1.775 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358864 0.032987 10.879 0.000
L1.Burgenland 0.006960 0.021909 0.318 0.751
L1.Kärnten -0.023445 0.011620 -2.018 0.044
L1.Niederösterreich 0.213173 0.045721 4.662 0.000
L1.Oberösterreich 0.200373 0.044634 4.489 0.000
L1.Salzburg 0.043950 0.023423 1.876 0.061
L1.Steiermark -0.014052 0.030544 -0.460 0.645
L1.Tirol 0.103912 0.024768 4.195 0.000
L1.Vorarlberg 0.071881 0.021256 3.382 0.001
L1.Wien 0.040255 0.039503 1.019 0.308
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039176 0.143022 0.191806 0.153846 0.121109 0.107660 0.064432 0.219218
Kärnten 0.039176 1.000000 -0.006944 0.131876 0.039537 0.094067 0.431670 -0.053542 0.097343
Niederösterreich 0.143022 -0.006944 1.000000 0.332835 0.144311 0.294159 0.101369 0.181105 0.314656
Oberösterreich 0.191806 0.131876 0.332835 1.000000 0.227353 0.325860 0.174513 0.166265 0.261126
Salzburg 0.153846 0.039537 0.144311 0.227353 1.000000 0.144992 0.116840 0.145708 0.125655
Steiermark 0.121109 0.094067 0.294159 0.325860 0.144992 1.000000 0.149597 0.136099 0.073254
Tirol 0.107660 0.431670 0.101369 0.174513 0.116840 0.149597 1.000000 0.113077 0.145797
Vorarlberg 0.064432 -0.053542 0.181105 0.166265 0.145708 0.136099 0.113077 1.000000 0.002367
Wien 0.219218 0.097343 0.314656 0.261126 0.125655 0.073254 0.145797 0.002367 1.000000